<?php
/**
 * Created by PhpStorm.
 * User: dingboxu
 * Date: 16/6/15
 * Time: 下午4:35
 */

namespace Utils;

class Util_session {
    const LIMIT_TIME = 3000;
    public function __construct($flag = true, $user = NULL,$name = NULL,$page = NULL) {
        $this->start ();
        if ($flag) {
            $ltime = $this->get ( "LOGINTIME" );
            if (! $ltime) {
                $this->end ();
                $this->logout ();
            }
            if ((time () - $ltime) > self::LIMIT_TIME) {
                $this->end ();
                $this->logout ();
            }
            $this->set ( "LOGINTIME", time () );
        } else {
            $this->set ( "LOGINTIME", time () );
            $this->set ( "USER", $user );
            $this->set('NAME', $name);
            $this->set('PAGE',$page);
        }
    }
    public function start() {
        @session_start ();
    }
    public function uunset() {
        session_unset ( $_SESSION );
    }
    public function set($key, $value) {
        $_SESSION [$key] = $value;
    }
    public function get($key) {
        if (! array_key_exists ( $key, $_SESSION ))
            return false;
        return $_SESSION [$key];
    }
    public function end() {
        session_destroy ();
    }
    public function logout() {
    }
}